#ifndef SQLITEUTIL_H
#define SQLITEUTIL_H

#include <QObject>
#include <QSqlDatabase>
#include <QSqlQuery>
#include <QList>
#include <QVariant>
#include <QSqlQueryModel>
#include <QSqlRecord>

class SqliteUtil : public QObject
{
    Q_OBJECT
public:

    const static QString TABLE_NAME;

    // 构造/析构函数
    explicit SqliteUtil(const QString database = "lock.db");
    ~SqliteUtil();

    bool createConnection(const QString conn);

    void createTable(const QString table_name);

    int executeInt(const QString query);
    int executeInt(const QString query, QList<QVariant> lstParameter);

    QSqlQuery executeQuery(const QString query);
    QSqlQuery executeQuery(const QString query, QList<QVariant> lstParameter);

    QSqlRecord executeRecord(const QString query);
    QSqlRecord executeRecord(const QString query, QVariant lstParameter);

    void executeQueryModel(QSqlQueryModel *p_queryModel, const QString query);
    void executeQueryModel(QSqlQueryModel *p_queryModel, QVariant id);

    void deleteTable(QString table_name);
private:
    QSqlDatabase m_db;
    QString m_strDb;

signals:
    void inserted();

};

#endif // SQLITEUTIL_H
